<script language="javascript">
function loadPage(url)
{
	$("#loader_area").show();
	$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');
    
    var url_arr = url.split("/");
    var module = url_arr[1];
    var param1 = url_arr[2];
  //  alert(param1);
    $.ajax({
		type: "POST",
		//cache: false,
    	url: 'controller.php?task=<?php echo base64_encode("loadmodule"); ?>',
    	data: ({url: url, param1: param1}),
    	success: function(html, textStatus, XMLHttpRequest){
    	   $("#bodyText").html(html);
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            $("#loader_area").hide();
        }
	});
}
    function validateQty()
{
	if($("#txtQty").val() == "") {
		alert("Please enter quantity");
                $("#txtQty").val("");
	} else if($("#txtQty").val() == 0) {
		alert("Please enter valid number ");
                $("#txtQty").val("");
	} else if(isNaN($("#txtQty").val())) {
		alert("Please enter a value");
                $("#txtQty").val("");
	} 
}


function saveCategory()
{
	var cat_desc = document.getElementById("txtCat");
	var parent_id = document.getElementById("cmbParentCat");
	var status = document.getElementById("cmbStatus");

	if(cat_desc.value == "") {
		alert("Category is required and cannot be blank");
		cat_desc.focus();
		return false;
	} else if(status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;
	} else {
		$("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');

		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("addcategory"); ?>',
	    	data: ({cat_desc: cat_desc.value, parent_id: parent_id.value, status: status.value}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                             alert("successfully Added the Category");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    	   		loadPage('category/index')
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
	}
}

function initiateUser()
{
	var username = $("#txtUsername");
	var password = $("#txtPassword");

	$("#loader_area").show();
	$("#loader_area").html('<img src="images/shared/loader.gif" /> Please wait while validating user');

	$.ajax({
		url: 'controller.php?task=<?php echo base64_encode("authuser"); ?>',
		type: 'POST',
		data: ({username: username.val(), password: password.val()}),
		success: function(data, textStatus, XMLHttpRequest) {
			if(data != '') {
				var return_str = data.split("|");
				if(return_str[1] == "error")
				{
					$("#loader_area").show();
					$("#loader_area").html(return_str[0]);
				} else if(return_str[1] == "success") {
					//$("#loader_area").hide();
					$("#loader_area").html(return_str[0]);
					location.href="adminview.php";
				}

			}
		},
		complete: function complete(XMLHttpRequest, textStatus){
			//$("#loader_area").hide();
		}
	})
}

function updatesearchstr()
{
		$("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');
		
		$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("createsearchstr"); ?>',
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {
    		       alert("successfully updated the search string");
                        $("#message_area").show();
	    	   	$("#message_area").html(data);
                        loadPage('product/index');
    	   	}
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});
 }

 function updatecredit()
{
		
               var userid = $("#userid");
	       var type = $("#type");
               var txtQty = $("#txtQty");

               if(txtQty.val()<=0){
                     alert("please enter a positive amount");
                     txtQty.focus();
                     return false;
               }
               else if(txtQty.val()==""){
                    alert("please enter a possitive amount");
                     txtQty.focus();
                      return false;
               }
               $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');
		$.ajax({
		type: "POST",
		data: ({userid: userid.val(), type: type.val(),txtQty:txtQty.val()}),
		url: 'controller.php?task=<?php echo base64_encode("updatecredit"); ?>',
    	        success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {
    		       alert("successfully updated the credit value ");
                        $("#message_area").show();
	    	   	$("#message_area").html(data);
                        loadPage('creditor/viewcreditaccount/'+userid.val());
    	   	}
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});
 }
 

function browseAll()
{
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("browsegallery"); ?>',
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#showimages").html(data);
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});
}

function updategalurl(id,val){

          $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');

		$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("updategalurl"); ?>',
                data: ({gallery_id: id,url:val}),
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {
                       alert("successfully updated the link");
                        $("#message_area").show();
	    	   	$("#message_area").html(data);
                        loadPage('gallery/index');
    	   	}
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});






}

function checkitemcode(code){

          $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');

		$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("checkitemcode"); ?>',
                data: ({itemcode: code}),
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {
                        if(data==1){
                            alert("The item code entered is already assigned to anothe product!");
                            $("#item_code").val('');
                            $("#item_code").focus();
                             $("#loader_area").hide();
                        }
                        else{
                            $("#loader_area").hide();

                        }
                        
                       // $("#message_area").show();
	    	   	//$("#message_area").html(data);
                        //loadPage('product/addproduct');
    	   	}
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});






}

function checkitemcodeupdate(code,productid){
          var item_code = $("#hdnitemcode").val();
          $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');

		$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("checkitemcodeupdate"); ?>',
                data: ({itemcode: code,productid:productid}),
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {
                        if(data==1){
                            alert("The item code entered is already assigned to anothe product!");
                            $("#item_code").val(item_code);
                            $("#item_code").focus();
                             $("#loader_area").hide();
                        }
                        else{
                            $("#loader_area").hide();

                        }
                        
                       // $("#message_area").show();
	    	   	//$("#message_area").html(data);
                        //loadPage('product/addproduct');
    	   	}
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});






}



function delGalImage(gallery_id)
{
	var msg = confirm("Are you sure you want to delete this image?")
	if (msg){
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("delgalleryimage"); ?>',
			data: ({gallery_id: gallery_id}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                            alert("successfully deleted the image");
	    			$("#message_area").html(data);
	    			loadPage('gallery/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            //$("#loader_area").hide();
	        }
		});
	} else {
		return false;
	}
}

function deletecategory(catid)
{
	var msg = confirm("Are you sure you want to delete this Category?");
	if (msg){
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("deletecategory"); ?>',
			data: ({catid: catid}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                              alert("successfully deleted the category");
	    			$("#message_area").html(data);
	    			loadPage('category/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            //$("#loader_area").hide();
	        }
		});
	} else {
		return false;
	}
}

function deleteproduct(productid)
{
	var msg = confirm("Are you sure you want to delete this Product");
	if (msg){
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("deleteproduct"); ?>',
			data: ({productid: productid}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                             alert("successfully deleted the product");
	    			$("#message_area").html(data);
	    			loadPage('product/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            //$("#loader_area").hide();
	        }
		});
	} else {
		return false;
	}
}
function delProductImage(productid,image_id)
{
	var msg = confirm("Are you sure you want to delete this image?")
	if (msg){
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("delproductimage"); ?>',
			data: ({productid: productid,image_id:image_id}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                            alert("successfully deleted  the product image");
	    			$("#message_area").html(data);
	    			loadPage('product/addimage/'+productid);
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            //$("#loader_area").hide();
	        }
		});
	} else {
		return false;
	}
}

function updateLanguage()
{
	var id = document.getElementById("keyid");
	var lang = document.getElementById("lang");
	var label = document.getElementById("keytext");
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("updatelanguage"); ?>',
		data: ({language_id: id.value, lang: lang.value, label: label.value}),
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#message_area").show();
    	   		$("#message_area").html(data);
    			loadPage('language/index');
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});
}

function saveNews()
{
	var news_title = $("#news_title");
	var newscontent_en = FCKeditorAPI.GetInstance("newscontent_en").EditorWindow.parent.FCK.GetHTML();
	var newscontent_sin = FCKeditorAPI.GetInstance("newscontent_sin").EditorWindow.parent.FCK.GetHTML();
	var newscontent_tamil = FCKeditorAPI.GetInstance("newscontent_tamil").EditorWindow.parent.FCK.GetHTML();
	var status = document.getElementById("cmbStatus");
	
	if(news_title.val() == "")
	{
		alert("News title is required and cannot be blank");
		news_title.focus();
		return false;
	} else if(newscontent_en == "") {
		alert("News content is required and cannot be blank");
		return false;
	} else if(status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("savenews"); ?>',
			data: ({news_title: news_title.val(), newscontent_en: newscontent_en, newscontent_sin: newscontent_sin, newscontent_tamil: newscontent_tamil, status: status.value}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {	    	   		
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('news/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            //$("#loader_area").hide();
	        }
		});
	}	
}
date
function getSubCat(ele)
{
	var category = document.getElementById(ele);
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("getsubcat"); ?>',
		data: ({cat_id: category.value}),
    	success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#subcat_loader").show();
    			$("#subcat_label").show();
    	   		$("#subcat_loader").html(data);    			
    	   	} else {
    	   		$("#subcat_loader").hide();
    	   	}
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
        }
	}); 
}

///////////

 
  


  /////////////////
function updateProduct()
{
	var product_title = $("#product_title");
        var item_code = $("#item_code");
        var discount = $("#discount");
	var product_desc_en = FCKeditorAPI.GetInstance("productdesc_en").EditorWindow.parent.FCK.GetHTML();
	var product_desc_detail = FCKeditorAPI.GetInstance("productdesc_detail").EditorWindow.parent.FCK.GetHTML();
	//var product_desc_tamil = FCKeditorAPI.GetInstance("productdesc_tamil").EditorWindow.parent.FCK.GetHTML();
	var product_price_lkr = $("#product_price_lkr");
	var product_qty = $("#product_qty");
	var category = document.getElementById("category");
	var subcat = document.getElementById("subcat");
	//var new_arrival = document.getElementById("newarrival");
	var status = document.getElementById("cmbStatus");

	var productid = document.getElementById("productid");
	
	if(product_title.val() == "")
	{
		alert("Product title is required and cannot be blank");
		product_title.focus();
		return false;
	} else if(product_desc_en == "") {
		alert("Product description is required and cannot be blank");
		product_desc_en.focus();
		return false;
	} else if(item_code == "") {
		alert("Product Itemcode  is required and cannot be blank");
		item_code.focus();
		return false;
	} else if(product_price_lkr.val() == "") {
		alert("Product price LKR is required and cannot be blank");
		product_price_lkr.focus();
		return false;
	} else if(product_price_lkr.val() != "" && isNaN(product_price_lkr.val())) {
		alert("Product price LKR can only contains numbers");
		product_price_lkr.focus();
		return false;
	} else if(product_qty.val() == "") {
		alert("Product quantity is required and cannot be blank");
		product_qty.focus();
		return false;
	} else if(product_qty.val() != "" && isNaN(product_qty.val())) {
		alert("Product quantity can only contains numbers");
		product_qty.focus();
		return false;
	} else if(category.selectedIndex == 0) {
		alert("Product category is required and cannot be blank");
		category.focus();
		return false;
	} else if(status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("updateproduct"); ?>',
			data: ({productid: productid.value, product_title: product_title.val(),item_code:item_code.val(), product_desc_en: product_desc_en, product_desc_detail: product_desc_detail,product_price_lkr: product_price_lkr.val(),product_qty: product_qty.val(), category: category.value, subcat: subcat.value, status: status.value, discount:discount.val()}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                    alert("successfully updated the product details");
	    			$("#message_area").show();
                    $("#message_area").html(data);
	    			//loadPage('product/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
	}
}
function processorder(orderid)
{ 
	
        var isdelivered ;
        var ispaid ;
         var  userid=$("#userid");
        var  ordertotal=$("#ordertotal");
        if(document.getElementById("isdelivered")==null){
            isdelivered=0;
        }
        else{
            if(document.getElementById("isdelivered").checked==true){
                 isdelivered=1;
        }
            else{
                 isdelivered=0;
            }
        }
        
        if(document.getElementById("ispaid").checked==true){
                 ispaid=1;
        }
        else{
             ispaid=0;
        }
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("processorder"); ?>',
			data: ({ ispaid: ispaid ,isdelivered: isdelivered,orderid:orderid,userid:userid.val(),ordertotal:ordertotal.val()}),
	    	success: function(data, textStatus, XMLHttpRequest){ 
	    	   	if(data != '') {
                            alert("successfully processed the order");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			
                                loadPage('order/view/'+orderid);
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});

}

function saveProduct()
{
        var item_code = $("#item_code");
      //  var num_pets = $("#product_qty");
	var product_title = $("#product_title");
        var product_title = $("#product_title");
	var product_desc_en = FCKeditorAPI.GetInstance("productdesc_en").EditorWindow.parent.FCK.GetHTML();
	var product_desc_detail = FCKeditorAPI.GetInstance("productdesc_detail").EditorWindow.parent.FCK.GetHTML();
	//var product_desc_tamil = FCKeditorAPI.GetInstance("productdesc_tamil").EditorWindow.parent.FCK.GetHTML();
	var product_price_lkr = $("#product_price_lkr");
	var product_qty = $("#product_qty");
        var Start_date=$("#Start_date");
        var End_date=$("#End_date");
        var category = document.getElementById("category");
	var subcat = document.getElementById("subcat");
	//var new_arrival = document.getElementById("newarrival");
	var status = document.getElementById("cmbStatus");

	var productid = document.getElementById("productid");
	
	if(product_title.val() == "")
	{
		alert("Product title is required and cannot be blank");
		product_title.focus();
		return false;
	} else if(product_desc_en == "") {
		alert("Product description is required and cannot be blank");
		product_desc_en.focus();
		return false;
	} else if(product_price_lkr.val() == "") {
		alert("Product price LKR is required and cannot be blank");
		product_price_lkr.focus();
		return false;
	} else if(product_price_lkr.val() != "" && isNaN(product_price_lkr.val())) {
		alert("Product price LKR can only contains numbers");
		product_price_lkr.focus();
		return false;
	} else if(product_qty.val() == "") {
		alert("Product quantity is required and cannot be blank");
		product_qty.focus();
		return false;
	} else if(product_qty.val() != "" && isNaN(product_qty.val())) {
		alert("Product quantity can only contains numbers");
		product_qty.focus();
		return false;
	} /*else if(category.selectedIndex == 0) {
		alert("Product category is required and cannot be blank");
		category.focus();
		return false;
	}*/ else if(status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("saveproduct"); ?>',
			data: ({item_code: item_code.val(),product_title: product_title.val(), product_desc_en: product_desc_en, product_desc_detail: product_desc_detail,product_price_lkr: product_price_lkr.val(),Start_date:Start_date.val(),End_date:End_date.val(),product_qty: product_qty.val(), category: category.value, subcat: subcat.value, status: status.value}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                                alert("successfully Added the product details");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('product/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
	}
}

function saveFeatures(productid)
{
        var arr = $("form").serializeArray();
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("savefeatures"); ?>',
			data: ({postarray: arr}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                              // alert(data);
                               alert("successfully Added the product features");
	  			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('product/addfeatures/'+productid);
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
	 
}

function deletestructurefield(structid,productid)
{
    if(confirm("Are you sure that you wan to permanantly delete this field?"))
        {
            $.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("deletefeature"); ?>',
			data: ({structid: structid,productid:productid}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                           //    alert(productid);
                           alert("successfully deleted  the product feature");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('product/addfeatures/'+productid);
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});


        }
		

}




function connectSAP()
{
	$("#loader").show(); 
    $("#loader").html("<b>Connecting to SAP Server</b><br /><img src='images/shared/loader_bar.gif' />");
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("loadbkfiles"); ?>',
		success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#process_area").show();      			
    			$("#loader").html(data);
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader").hide();
        }
	});
}

function importFromBackup()
{
	//$("#loader").show(); 
    //$("#loader").html("<b>Connecting to SAP Server</b><br /><img src='images/shared/loader_bar.gif' />");
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("loadbkfiles"); ?>',
		success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#loader").show();      			
    			$("#loader").html(data);
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader").hide();
        }
	});
}

function importProcess(file)
{
	$("#loader").show(); 
    $("#loader").html("<b>Updating Item Master table...This will take few minutes.</b><br /><br /><img src='images/shared/loader_bar.gif' />");
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("processbackup"); ?>',
		data: ({filename: file}),
		success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#loader").show();      			
    			$("#loader").html(data);
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader").hide();
        }
	});
}

function loadPaginator(url, pagenum)
{
	$.ajax({
		type: "POST",
		//cache: false,
    	url: url,
    	data: ({url: url, pagenum: pagenum}),
    	success: function(html, textStatus, XMLHttpRequest){
    	   $("#bodyText").html(html);
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader_area").hide();
        }
	});
}

function updateNews(news_id)
{
	var news_title = $("#news_title");
	var news_desc_en = FCKeditorAPI.GetInstance("newscontent_en").EditorWindow.parent.FCK.GetHTML();
	var news_desc_sin = FCKeditorAPI.GetInstance("newscontent_sin").EditorWindow.parent.FCK.GetHTML();
	var news_desc_tamil = FCKeditorAPI.GetInstance("newscontent_tamil").EditorWindow.parent.FCK.GetHTML();
	var status = document.getElementById("cmbStatus");
	
	if(news_title.val() == "")
	{
		alert("News title is required and cannot be blank");
		news_title.focus();
		return false;
	} else if(news_desc_en == "") {
		alert("News description is required and cannot be blank");
		news_desc_en.focus();
		return false;
	} else if(status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("updatenews"); ?>',
			data: ({news_id: news_id, news_title: news_title.val(), news_desc_en: news_desc_en, news_desc_sin: news_desc_sin, news_desc_tamil: news_desc_tamil, status: status.value}),
			success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {	    	   		
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('news/index');
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});	
	}	
}

function deleteNews(news_id)
{
	var msg = confirm("Are you sure you want to delete this record?")
	if (msg){
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("delnews"); ?>',
			data: ({news_id: news_id}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {	    	   		
	    	   		$("#message_area").show();
	    			$("#message_area").html(data);	    			
	    			loadPage('news/index');
	    	   	}	
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            //$("#loader_area").hide();
	        }
		});
	} else {
		return false;
	}
}

function importExchangeRates()
{
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("importrates"); ?>',
		success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#loader").show();      			
    			$("#loader").html(data);
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader").hide();
        }
	});
}

function continueInportRates()
{
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("importrates2"); ?>',
		success: function(data, textStatus, XMLHttpRequest){
    	   	if(data != '') {	    	   		
    			$("#loader").show();      			
    			$("#loader").html(data);
    	   	}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader").hide();
        }
	});
}

function abortratesImportProcess()
{
	$("#msg_box2").show();      			
	$("#msg_box2").html("<span class='success' style='font-size: 10px;'>Rates Import process has been aborted.</span>");
}


function saveUser()
{      // alert("vhfkghkf");
      // var user_type=document.getElementById("user_type"); //$("#user_type");
        var user_email=$("#user_email");
        // alert(user_email);
        var user_passwd  =$("#user_passwd ");
        var confirm_user_passwd=$("#confirm_user_passwd");
        var secret_question =$("#secret_question ");
        var secret_answer =$("#secret_answer");
        var user_firstname =$("#user_firstname");
        var user_lastname =$("#user_lastname");
      //  var Designation =$("#Designation");
      //  var companyname =$("#companyname ");
      //  var companyaddress=$("#companyaddress");
        var user_phone=$("#user_phone");
        var user_fax =$("#user_fax");
      //  var typeofbusiness =$("#typeofbusiness");
      //  var industry=$("#industry");
      //  var prefferedpayment =$("#prefferedpayment ");
        var iscreditor =$("#iscreditor ");
        var Status = document.getElementById("cmbStatus");
       // var profession =$("#profession");
        var nicno =$("#nicno");
        var user_address =$("#user_address");
           //  alert("vhfkghkf");
         if(document.getElementById("iscreditor").checked==true){
                 iscreditor=1;
                  //alert("1");
        }
        else{
             iscreditor=0;
              //alert("2");
        }
            // alert("vhfkghkf");

	 if(user_email.val() == "")
	{
		alert("Email cannoty be blank");
                user_email.focus();
		return false;
	} else if(user_passwd.val() == "") {
		alert("Password cannot be blank");
		user_passwd.focus();
		return false;
	}  else if(user_passwd.val() == "") {
		alert("EPassword cannot be blank");
		user_passwd.focus();
		return false;
	}  else if(user_passwd.val() != confirm_user_passwd.val()) {
		alert("Passwor confirmaton failed");
		user_passwd.focus();
		return false;
	}  else if(secret_question.val() == "") {
		alert("Secret Question cannot be blank");
		secret_question.focus();
		return false;
	}  else if(secret_answer.val() == "") {
		alert("Secret Answer cannot be blank");
		secret_answer.focus();
		return false;
	}  else if(user_firstname.val() == "") {
		alert("First Name cannot be blank");
		user_firstname.focus();
		return false;
	} else if(user_lastname.val() == "") {
		alert("last Name cannot be blank");
		user_lastname.focus();
		return false;
	} else if(Status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		Status.focus();
		return false;

	}
            else if(nicno.val() == "") {
                    alert("NIC no is required and cannot be blank");
                    nicno.focus();
                    return false;

            }else if(user_address.val()=="") {
                    alert("User Address is required and cannot be blank");
                    user_address.focus();
                    return false;

            }
        
         else if(user_phone.val() == "") {
                            alert("Phone cannot be blank");
                            user_phone.focus();
                            return false;
                    }else if(user_fax.val() == ""  ) {
                            alert("Fax cannot be blank");
                            user_fax.focus();
                            return false;
                    }
            
        
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("saveuser"); ?>',
	    	data: ({user_email:user_email.val(),user_passwd :user_passwd .val(),confirm_user_passwd:confirm_user_passwd.val(),secret_question :secret_question .val(),secret_answer:secret_answer.val(),user_firstname:user_firstname.val(),user_lastname:user_lastname.val(),user_phone:user_phone.val(),user_fax:user_fax.val(),iscreditor :iscreditor,Status:Status.value,user_address:user_address.val(),nicno:nicno.val()}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                            alert("successfully Added the user");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('user/index');
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
	
}
function updateUser()
{
        var user_type=document.getElementById("user_type"); //$("#user_type");
        var user_id=$("#userid");
        var user_email=$("#user_email");
        var user_passwd  =$("#user_passwd ");
        var confirm_user_passwd=$("#confirm_user_passwd");
        var secret_question =$("#secret_question ");
        var secret_answer =$("#secret_answer");
        var user_firstname =$("#user_firstname");
        var user_lastname =$("#user_lastname");
        var Designation =$("#Designation");
        var companyname =$("#companyname ");
        var companyaddress=$("#companyaddress");
        var user_phone=$("#user_phone");
        var user_fax =$("#user_fax");
        var typeofbusiness =$("#typeofbusiness");
        var industry=$("#industry");
        var prefferedpayment =$("#prefferedpayment");
        var iscreditor=$("#iscreditor");
        var profession =$("#profession");
        var nicno =$("#nicno");
        var user_address =$("#user_address");
        var Status = document.getElementById("cmbStatus");

     if(document.getElementById("iscreditor").checked==true){
                 iscreditor=1;
        }
        else{
             iscreditor=0;
        }
	 if(user_email.val() == "")
	{
		alert("Email cannot be blank");
                user_email.focus();
		return false;
	} else if(user_passwd.val() != "") {
	     if(user_passwd.val() != confirm_user_passwd.val()) {
		alert("Password confirmaton failed");
		user_passwd.focus();
		return false;
	      }
	} else if(secret_question.val() == "") {
		alert("Secret Question cannot be blank");
		secret_question.focus();
		return false;
	}  else if(secret_answer.val() == "") {
		alert("Secret Answer cannot be blank");
		secret_answer.focus();
		return false;
	}  else if(user_firstname.val() == "") {
		alert("First Name cannot be blank");
		user_firstname.focus();
		return false;
	} else if(user_lastname.val() == "") {
		alert("last Name cannot be blank");
		user_lastname.focus();
		return false;
	} else if(Status.selectedIndex == 0) {
		alert("Status is required and cannot be blank");
		Status.focus();
		return false;
	} 
        else if(nicno.val() == "") {
                    alert("NIC no is required and cannot be blank");
                    nicno.focus();
                    return false;

            }else if(user_address.val()=="") {
                    alert("User Address is required and cannot be blank");
                    user_address.focus();
                    return false;

            }
                else if(user_phone.val() == "") {
                            alert("Phone cannot be blank");
                            user_phone.focus();
                            return false;
                    }
             
		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("updateuser"); ?>',
	    	data: ({user_id:user_id.val(),user_email:user_email.val(),user_passwd :user_passwd .val(),confirm_user_passwd:confirm_user_passwd.val(),secret_question :secret_question .val(),secret_answer:secret_answer.val(),user_firstname:user_firstname.val(),user_lastname:user_lastname.val(),user_phone:user_phone.val(),user_fax:user_fax.val(),Status:Status.value,user_address:user_address.val(),nicno:nicno.val()}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                            alert("successfully updated the user");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
	    			loadPage('user/index');
	    	   	}
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});

}


function renameCategory(catid)
{
	$("#extcatlabel_"+catid).hide();
	$("#lblcategory_"+catid).show();
	
}

function updateCatLabel(catid)
{
	var catlabel = $("#txtCatlabel_"+catid);
	$.ajax({
		type: "POST",
		url: 'controller.php?task=<?php echo base64_encode("renamecategory"); ?>',
		data:({catid: catid, category: catlabel.val()}),
		success: function(data, textStatus, XMLHttpRequest){
			if(data != '') {	    	   		
    			$("#lblcategory_"+catid).hide();   			
    			$("#extcatlabel_"+catid).show();
    			$("#extcatlabel_"+catid).html(data);
			}	
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            //$("#loader").hide();
        }
	});	
}

function openPrintWindow(url, name, menubar, resizable, location, width, height)
{
	window.open(url, name,"menubar="+menubar+",resizable="+resizable+",location="+location+",width="+width+",height="+height);
}

 function cancelorder(orderid)

    {
	if(confirm("Are you sure that you want to cancel this order?")==false) {

		return false;
	} else {
		$("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');

		$.ajax({
			type: "POST",
			url: 'controller.php?task=<?php echo base64_encode("cancelorder"); ?>',
	    	data: ({id: orderid}),
	    	success: function(data, textStatus, XMLHttpRequest){
	    	   	if(data != '') {
                            // alert("Order cancelled");
	    			$("#message_area").show();
	    	   		$("#message_area").html(data);
                              //  alert("1");
	    	   		loadPage('order/index');
	    	   	}
                            else{
                               // alert("2");
                            }
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            $("#loader_area").hide();
	        }
		});
	}


    }
</script>